package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.UserDto;
import com.zzyl.service.UserService;
import com.zzyl.vo.UserVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@Api(tags = "用户管理")
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    UserService userService;

    //用户分页
    @PostMapping("/page/{pageNum}/{pageSize}")
    @ApiOperation(value = "用户分页",notes = "用户分页")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userDto",value = "用户DTO对象",required = false,dataType = "UserDto"),
            @ApiImplicitParam(paramType = "path",name = "pageNum",value = "页码",example = "1",dataType = "Integer"),
            @ApiImplicitParam(paramType = "path",name = "pageSize",value = "每页条数",example = "10",dataType = "Integer")
    })
    public ResponseResult<PageResponse<UserVo>> findRoleVoPageResponse(
            @RequestBody UserDto userDto,
            @PathVariable("pageNum") Integer pageNum,
            @PathVariable("pageSize") Integer pageSize) {
        PageResponse<UserVo> pageResponse = userService.findUserPage(userDto, pageNum, pageSize);
        log.info("那一页:{} ,每页条数 {}",pageNum,pageSize);
        return ResponseResult.success(pageResponse);
    }
    //用户添加
    @PutMapping
    @ApiOperation(value = "用户添加",notes = "用户添加")
    @ApiImplicitParam(name = "userDto",value = "用户DTO对象",required = true,dataType = "UserDto")
    public ResponseResult<UserVo> addUser(@RequestBody UserDto userDto) {
        UserVo userVo = userService.addUser(userDto);
        return ResponseResult.success(userVo);
    }
    //用户删除
    @DeleteMapping("/remove/{userIds}")
    @ApiOperation(value = "用户删除",notes = "用户删除")
    public ResponseResult removeUser(@PathVariable("userIds") Long userIds) {
        userService.deleteUserById(userIds);
        return ResponseResult.success();
    }
    //用户修改
    @PatchMapping
    @ApiOperation(value = "用户修改",notes = "用户修改")
    @ApiImplicitParam(name = "userDto",value = "用户DTO对象",required = true,dataType = "UserDto")
    public ResponseResult<Boolean> updateUser(@RequestBody UserDto userDto) {
        Boolean aBoolean = userService.updateUser(userDto);
        return ResponseResult.success(aBoolean);
    }
}
